package com.cqw.commontest.sort;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-09 15:08
 * @Description:
 */
public class Test1 {

    public static void main(String[] args) throws ParseException {
        //冒泡排序
        int[] arr = {1, 6, 2, 5, 3, 8};
        int temp;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j + 1] < arr[j]) {
                    temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));


        //选择排序
        SimpleDateFormat slf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ArrayList<Person> peopleList = new ArrayList<>();
        peopleList.add(new Person(1L,slf.parse("2021-06-10 11:14:26")));
        peopleList.add(new Person(2L,slf.parse("2021-06-09 11:14:26")));
        peopleList.add(new Person(3L,slf.parse("2021-06-11 11:14:26")));
        peopleList.add(new Person(4L,slf.parse("2021-06-10 00:00:00")));

        System.out.println(peopleList);

        List<Person> collect = peopleList.stream().filter(person -> {
            SimpleDateFormat slf1 = new SimpleDateFormat("yyyy-MM-dd");
            try {
                String old = slf1.format(person.getCreateTime());
                String now = slf1.format(new Date());
                return old.equals(now);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }).collect(Collectors.toList());

        System.out.println(collect);


        List<String> collect1 = peopleList.stream()
                .map(person -> "A" + person.getId()).collect(Collectors.toList());

        System.out.println(collect1);


    }


}
